package cn.redragon.soa.data.entity;

import java.io.Serializable;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentityGenerator;

public class AssignedIdentityGenerator extends IdentityGenerator {

    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
        if (object instanceof IdEntity) {
            IdEntity entity = (IdEntity) object;
            if (entity.getId() != null) {
                return entity.getId();
            }
        }
        return super.generate(session, object);
    }
}
